package com.itany.corejava.day15;

public class TestDeadLock {


    public static void main(String[] args) {
        Object a=new Object();
        Object b=new Object();

        MyThread1 t1=new MyThread1(a,b);
        MyThread2 t2=new MyThread2(a,b);

        t1.start();
        t2.start();
    }





}


class MyThread1 extends  Thread{

    private Object a;
    private Object b;

    public MyThread1(Object a, Object b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public void run() {
        synchronized (a) {

            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

            synchronized (b) {
                System.out.println("aaa");
            }
        }
    }
}

class MyThread2 extends  Thread{

    private Object a;
    private Object b;

    public MyThread2(Object a, Object b) {
        this.a = a;
        this.b = b;
    }

    @Override
    public void run() {
        synchronized (b) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            synchronized (a) {
                System.out.println("bbb");
            }
        }
    }
}